package com.cloudcc.mobile.weight;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.cloudcc.mobile.R;


/** 
* @Description: listview的空布局 
* @author wangzhiqiang
* @date 2015-12-14 下午5:15:13 
*/
public class EmptyLayout extends LinearLayout {
	private TYPESTATE mType=TYPESTATE.HIDE;

	private LinearLayout containerResult;
	private RelativeLayout containerLoading;
	
	public enum TYPESTATE{
		HIDE,LOADING,EMPTY
	}

	public EmptyLayout(Context context) {
		this(context,null);
	}

	public EmptyLayout(Context context, AttributeSet attrs) {
		this(context, attrs,0);
	}

	public EmptyLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		stepViews();
	}

	private void stepViews() {
		LayoutInflater.from(getContext()).inflate(R.layout.views_load_cloudcc_footer, this);
		containerResult = (LinearLayout) findViewById(R.id.loading_result_container);
		containerLoading = (RelativeLayout) findViewById(R.id.loading_load_container);
	}

	public void hide() {
		mType = TYPESTATE.HIDE;
		containerResult.setVisibility(View.GONE);
		containerLoading.setVisibility(View.GONE);
		setVisibility(View.GONE);
	}
	public void loading(){
		mType = TYPESTATE.LOADING;
		setVisibility(VISIBLE);
		containerResult.setVisibility(View.GONE);
		containerLoading.setVisibility(View.VISIBLE);
	}
	public void empty(){
		mType = TYPESTATE.EMPTY;
		setVisibility(VISIBLE);
		View iamge = containerResult.findViewById(R.id.no_result_image);
		iamge.setVisibility(View.VISIBLE);
		containerResult.setVisibility(View.VISIBLE);
		containerLoading.setVisibility(View.GONE);
	}

	public TYPESTATE getEmptyType() {
		return mType;
	}
	public void setEmptyType(TYPESTATE type) {
		if (type==TYPESTATE.HIDE) {//hide
			hide();
		}else if(type==TYPESTATE.LOADING){//loading
			loading();
		}else if(type==TYPESTATE.EMPTY){//no data
			empty();
		}
	}

	@Override
	public void setVisibility(int visibility) {
		if (visibility == View.GONE)
			mType = TYPESTATE.HIDE;
		super.setVisibility(visibility);
	}

}
